<!-- 用例日志列表信息 -->
<template>
  <div class="div_box">
    <div style="min-width: 1600px;">
      <!-- 头部搜索框 -->
      <el-form :inline="true" :model="searchLogForm" @keyup.enter.native="getLogList()">
        <el-form-item>
          <el-select v-model="searchLogForm.taskId" clearable filterable placeholder="测试任务，精确查询">
            <el-option
              v-for="item in taskList"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            />
          </el-select></el-form-item>
        <el-form-item>
          <el-input v-model="searchLogForm.caseName" placeholder="用例名称，模糊查询" clearable />
        </el-form-item>
        <el-form-item>
          <el-input v-model="searchLogForm.caseNum" placeholder="用例编号，精确查询" clearable />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getLogList()">查询</el-button>
          <!-- <el-button type="danger" :disabled="logListSelections.length <= 0" @click="deleteHandle()">批量删除</el-button> -->
        </el-form-item>
      </el-form>
      <!-- table展示页 -->
      <el-table v-loading="logListLoading" :data="logList" border style="width: 100%;" @selection-change="selectionChangeHandle">
        <el-table-column type="selection" header-align="center" align="center" width="50" />
        <el-table-column prop="id" header-align="center" align="center" label="日志ID" sortable width="90" />
        <el-table-column prop="caseName" header-align="center" align="center" label="用例名称" sortable width="400" />
        <el-table-column prop="taskName" header-align="center" align="center" label="关联任务" sortable />
        <el-table-column prop="demandName" header-align="center" align="center" label="关联需求" sortable />
        <el-table-column prop="executor" header-align="center" align="center" label="执行人" sortable />
        <el-table-column prop="result" header-align="center" align="center" label="结果" sortable>
          <template slot-scope="scope">
            <el-tag v-if="scope.row.result === 1" type="success">已通过</el-tag>
            <el-tag v-if="scope.row.result === 0" type="info">未执行</el-tag>
            <el-tag v-if="scope.row.result === 3" type="warning">阻塞中</el-tag>
            <el-tag v-if="scope.row.result === 2" type="danger">已失败</el-tag>
          </template>
        </el-table-column>
        <el-table-column fixed="right" header-align="center" align="center" width="200" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="getDetail(scope.row)">查看</el-button>
            <!-- <el-button type="text" size="small" @click="todo(scope.row)">修改</el-button>
            <el-button type="text" size="small" @click="todo(scope.row)">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页功能区 -->
      <el-pagination
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
      />
    </div>
  </div>
</template>

<script>
import { searchAll } from '@/api/auto/log.js'
import { listTask } from '@/api/auto/task.js'
export default {
  name: 'AutoCaseLog',
  data() {
    return {
      logListSelections: [],
      searchLogForm: {},
      logList: [],
      logListLoading: false,
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      taskList: []
    }
  },
  created() {
    this.getLogList()
    this.getTaskList()
  },
  activated() {
    this.getLogList()
    this.getTaskList()
  },
  methods: {
    getTaskList() {
      listTask('', 1, 100).then(respnose => {
        if (respnose && respnose.code === 200) {
          this.taskList = respnose.data.content
        }
      })
    },
    getLogList() {
      this.logListLoading = true
      this.searchLogForm.pageNo = this.pageIndex
      this.searchLogForm.pageSize = this.pageSize
      searchAll(this.searchLogForm).then(respnose => {
        if (respnose && respnose.code === 200) {
          this.logList = respnose.data.content
          this.totalPage = respnose.data.totalElements
        } else {
          this.logList = []
          this.totalPage = 0
          this.$message.error(respnose.message)
        }
        this.logListLoading = false
      })
    },
    // 查看详情
    // 多选
    selectionChangeHandle(val) {
      this.logListSelections = val
    },
    // 每页数变化
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getLogList()
    },
    // 当前页变化
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getLogList()
    },
    // 批量删除方法 TODO
    deleteHandle(id) {
      var ids = id ? [id] : this.logListSelections.map(item => {
        return item.id
      })
      this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.$message('todo')
      }).catch(() => {})
    },
    getDetail(row) {
      // 这里不要删除缓存了
      // this.$store.dispatch('tagsView/delView', { name: 'AutoCaseLogDetail', path: '/auto/auto-case-log-detail' })
      this.$nextTick(() => {
        this.$router.push({
          name: 'AutoCaseLogDetail',
          params: {
            logId: row.id
          }
        })
      })
    }
  }
}
</script>

<style scoped="scoped">
.div_box {
  border: 1px solid #eee;
  padding-left: 15px;
  padding-right: 15px;
  padding-top: 15px;
  padding-bottom: 10px;
  margin-top: 10px;
  margin-bottom: 10px;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: auto;
}
</style>
